package com.example.backend.common.utils;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 请求工具类
 */
public class RequestUtils {
    
    /**
     * 获取请求对象
     */
    public static HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
    
    /**
     * 获取User-Agent
     */
    public static String getUserAgent() {
        return getRequest().getHeader("User-Agent");
    }
    
    /**
     * 获取请求URL
     */
    public static String getRequestUrl() {
        return getRequest().getRequestURL().toString();
    }
    
    /**
     * 获取请求方法
     */
    public static String getMethod() {
        return getRequest().getMethod();
    }
    
    /**
     * 获取请求参数
     */
    public static String getQueryString() {
        return getRequest().getQueryString();
    }
} 